<template>
<div class="login-wrap">
  <div class="container">
  <div class="login-head">
    <a href="/#/index">
      <img src="/imgs/login-logo.png" alt="">
    </a>
  </div>
</div>
  <div class="login-body">
    <div class="container">
      <div class="login-from">
        <h3>
          <span class="checked">账号登录</span> <span class="spe-line">|</span> <span>扫码登录</span>
        </h3>
        <div class="input">
          <input type="text" placeholder="请输入账号" v-model="username">
        </div>
        <div class="input">
          <input type="password" placeholder="请输入密码" v-model="password">
        </div>
          <div class="btn"  @click="account">登录</div>
        <div class="tips">
          <div class="checked" @click="registered">手机短信登录/注册</div>
          <div><span>立即注册</span> <span class="spe-line">|</span> <span>忘记密码</span></div>
        </div>
      </div>
    </div>
  </div>
  <div class="login-footer">
    <div class="container">
      <div class="footer-link">
        <a href="">小王咚咚咚主页</a><span>|</span>
        <a href="">Vue全栈课程</a><span>|</span>
        <a href="">React全家桶课程</a><span>|</span>
        <a href="">微信支付专项课程（H5+小程序+node+mango）</a>
      </div>
      <div class="copyright">Copyright ©2019 <span class="domain">mi.futurefe.com</span> All Rights Reserved.</div>
    </div>
  </div>
</div>
</template>

<script>
export default {
name: "login",
  data(){
  return{
    username:'',
    password:'',
    userId:''
  }
  },
  methods:{
    account(){
      let {username,password} = this;
      this.axios.post('/user/login',{
        username,
        password
      }).then((res)=>{
        // console.log(res)
        this.$cookie.set('userId',res.id,{expires:'1M'})
        this.$store.dispatch('saveUsername',res.username)
        // console.log(this.$store.state.username)
        this.$router.push('/index')
      })
    },
    registered(){
      let {username,password} = this;
      let email = '2501246220@qq.com';
      this.axios.post('/user/register',{
        username,
        password,
        email
      }).then(()=>{
        console.log('注册成功')
        })
    }
  }
}
</script>

<style lang="scss" scoped>
@import "../assets/scss/base.scss";
@import "../assets/scss/mixin.scss";
@import "../assets/scss/login.scss";
</style>
